#include "msgq.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

#define QUEUE_ID	3

int main(int argc, char **argv)
{
	int msgid;
	key_t key;
	int i;
	struct data_st rd;


	if (argc < 2)
		return -1;

	key = ftok(FILENAME, PROC_ID);
	
	msgid = msgget(key, atoi(argv[1]));
	if (-1 == msgid) {
		perror("Error gettin message");
		exit(1);
	}

	while (1) {
		msgrcv(msgid, &rd, MAXSIZE, -5, 0);
		printf("mtype: %ld, mtext: %s\n", rd.mtype, rd.mtext);
	}

	// 销毁消息队列
	// msgctl(0, IPC_RMID, NULL);

	return 0;
}
